package com.mk.controller.admin;

import com.mk.entity.Illegal;
import com.mk.result.Result;
import com.mk.service.IIllegalService;
import com.mk.vo.IllegalVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 客户端违法处理业务
 */
@RestController("adminIllegalController")
@RequestMapping("/admin/illegal")
@RequiredArgsConstructor
public class IllegalController {

    private final IIllegalService illegalService;

    /**
     * 新增罚款信息
     * @param illegal
     * @return
     */
    @CrossOrigin
    @PostMapping("/save")
    public Result save(@RequestBody Illegal illegal) {
        illegal.setCreateTime(LocalDateTime.now());
        illegal.setUpdateTime(LocalDateTime.now());
        illegalService.save(illegal);
        return Result.success();
    }

    /**
     * 根据id查询罚款信息
     * @param id
     * @return
     */
    @CrossOrigin
    @GetMapping("/select")
    public Result<Illegal> selectById(Long id) {
        Illegal illegal = illegalService.getById(id);
        return Result.success(illegal);
    }

    /**
     * 批量删除罚款信息
     * @param ids
     * @return
     */
    @CrossOrigin
    @DeleteMapping("/delete/ids")
    public Result deleteByIds(@RequestBody List<Long> ids) {
        illegalService.removeBatchByIds(ids);
        return Result.success();
    }

    /**
     * 根据id更新罚款信息
     * @param illegal
     * @return
     */
    @CrossOrigin
    @PutMapping("/update")
    public Result update(@RequestBody Illegal illegal) {
        illegal.setUpdateTime(LocalDateTime.now());
        illegalService.updateById(illegal);
        return Result.success();
    }

    //TODO 分页查询罚款信息
}
